import 'package:flutter/material.dart';
import 'package:flutter_swiper_null_safety_flutter3/flutter_swiper_null_safety_flutter3.dart';
import 'package:meiyunapp/common/url_base.dart';
import 'package:meiyunapp/entity/home_top_data_entity.dart';

///滑动轮播图
class SwiperComponent extends StatelessWidget {
  final List<HomeTopDataBanners>? urls;

  const SwiperComponent(this.urls, {Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    if (urls == null || urls!.isEmpty) {
      return const SizedBox();
    }
    return SizedBox(
      child: AspectRatio(
        aspectRatio: 16 / 9,
        child: Swiper(
          itemCount: urls!.length,
          itemBuilder: (BuildContext context, int index) {
            return Image.network(UrlBase.getImage(urls![index].image),
                fit: BoxFit.fill);
          },
          // 无限循环
          loop: true,
          // 自动轮播
          autoplay: true,
        ),
      ),
    );
  }
}
